package com.chenzhiling.study.datasource.LocalFile

import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.sources.{BaseRelation, RelationProvider}

/**
 * @Author: CHEN ZHI LING
 * @Date: 2021/8/26
 * @Description: 本地文件数据源
 */
class DefaultSource extends RelationProvider{
  override def createRelation(sqlContext: SQLContext, parameters: Map[String, String]): BaseRelation = {
    val params: Map[String, String] = initParams(parameters)
    new LocalFileRelation(sqlContext,params)
  }



  private def checkPath(parameters: Map[String, String]): String = {
    parameters.getOrElse("path",
      throw new IllegalArgumentException("path must be specified."))
  }
  def initParams(parameters: Map[String, String]): Map[String, String] = {
    val path: String = checkPath(parameters)
    val params: Map[String, String] = Map[String, String](
      "path" -> path)
    params
  }
}
